﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PokerClient.Connection.CommandHandlers;
using PokerClient.Connection.Interfaces;
using PokerClient.VisualDisp;
using PokerClient.Commands.CommandFactories;
using PokerClient.Commands.CommandHandlers;

namespace PokerClient.Connection.CommandFactories
{
	public enum States
	{
		AUTH,
		REGISTER,
		TABLE,
		NOTHING,
		STATISTICS,
		QUIT,
		SEAT,
		CURRGAME,
		CHIPTABLE,
		CHECKCALL,
		RAISE,
		FOLD,
		TURN,
		SHOWHANDS,
		WINNER,
		ROUND,
		REVEAL,
		HANDS
	}
	public class Handlerfact 
	{
		
		States e = States.NOTHING;
		
		public IHandle getHandler(String commands,MainWindow window,Lobby lobby,Table table,Client myClient)
		{
			IHandle handler = null;
			String[] temp = commands.ToUpper().Split(' ');
			switch (temp[0])
			{
				case "AUTH-ACK":
				case "AUTH-FAIL":
					e = States.AUTH;
					handler = new authProtHandles(window, myClient);
					break;
				case "REGISTER-FAIL":
				case "REGISTER-ACK":
					e = States.REGISTER;
					handler = new regProtHandles(myClient, window);
					break;
				case "JOINTABLE-ACK":
				case "JOINTABLE-FAIL":
				case "PARTTABLE-ACK":
				case "PARTTABLE-FAIL":
				case "TABLELIST":
					e = States.TABLE;
					handler = new tableHandler(lobby, myClient);
					break;
				
				case "STATISTICS":
					e = States.STATISTICS;
					handler = new PlayerStatHandler(lobby, myClient);
					break;
				case "SHOWHANDS":
					e = States.SHOWHANDS;
					handler = new showHandsHandler(table, myClient);
					break;
				case "WINNER":
					e = States.WINNER;
					handler = new winnerHandler(table, myClient);
					break;
				case "CURRENTGAME":
					e = States.CURRGAME;
					handler = new currGameHandler(table, myClient);
					break;
				case "CHIPTABLE":
					e = States.CHIPTABLE;
					handler = new chipTablehandler(table);
					break;
				case "TURN":
					e = States.TURN;
					handler = new turnHandler(table);
					break;
				case "REVEAL":
					e = States.REVEAL;
					handler = new revealHandler(table);
					break;
				case "HAND":
					e = States.HANDS;
					handler = new HandHandler(myClient, table);
					break;
				case "ROUND":
					e = States.ROUND;
					handler = new roundHandler(table);
					break;
				case "CHECK":
				case "CALL":
					e = States.CHECKCALL;
					handler = new checkCallHandler(table);
					break;
				case "FOLD":
					e = States.FOLD;
					handler = new foldHandler(table);
					break;
				case "RAISE":
					e = States.RAISE;
					handler = new raiseHandler(table);
					break;
				case "SEATDOWNTABLE-ACK":
				case "SEATDOWNTABLE-FAIL":
				case "SEATUPTABLE-ACK":
				case "SEATUPTABLE-FAIL":
					e = States.SEAT;
					handler = new seatHandler(table, myClient);
					break;
				case "PLAYERLIST":
					e = States.NOTHING;
					table.allocatePlayers(commands);
					break;
				default:
					e = States.QUIT;
					break;
			}

			return handler;
		}

		public States getState
		{
			set
			{
				this.e = value;
			}
			get
			{
				return this.e;
			}
		}

	
	}
}
